package com.fire.shop.service.impl;

import com.fire.shop.domain.Device;
import com.fire.shop.mapper.DeviceMapper;
import com.fire.shop.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeviceServiceImpl implements DeviceService {

    @Autowired
    private DeviceMapper deviceMapper;

    /**
     * 查询所有设备的业务方法
     * List<Device> queryAllDevice(Device device)
     * 对查询到的所有shop进行缓存，缓存到redis的键为all:device
     * */
    @Cacheable(key = "'all:device'")
    @Override
    public List<Device> queryAllDevice(Device device) {
        // 查询所有设备
        return deviceMapper.queryAllDevice(device);
    }

    /**
     * 根据id删除设备
     * */
    @Override
    public int deleteById(String id) {
        // 根据id删除设备
        return deviceMapper.deleteById(id);
    }

    /**
     * 添加设备
     * */
    @Override
    public int insert(Device device) {
        // 添加设备
        return deviceMapper.insert(device);
    }

    /**
     * 更新设备
     * */
    @Override
    public int updateById(Device device) {
        // 更新设备
        return deviceMapper.updateById(device);
    }

    /**
     * 根据id更新设备状态
     * */
    @Override
    public int updateStatusById(Device device) {
        // 根据id更新设备状态
        return deviceMapper.updateStatusById(device);
    }

    /**
     * 根据id更新设备服务时间
     * */
    @Override
    public int updateServiceTimeById(Device device) {
        // 根据id更新设备服务时间
        return deviceMapper.updateServiceTimeById(device);
    }
}
